import http from '@/utils/axios'
import { BasicResponseModel, UploadFileParams } from './model/basicModel'
import {
  DirectoryListParams,
  AddDirmanagementParams,
  UpdateManagementParams,
  DirectoryStartParams,
  SponsorDirectoryFlowParams
} from '@/api/model/directoryModel'
import { ContentTypeEnum } from '@/enums/httpEnum'

enum Api {
  List = '/statement/dirmanagement/list', // 查询目录管理列表
  Detail = '/statement/dirmanagement/getById', // 查询目录详情
  Add = '/statement/dirmanagement/add', // 添加目录文件
  Delete = '/statement/dirmanagement/delete', // 删除目录
  Sponsor = '/statement/dirmanagement/start', // 目录发起流程
  Dept = '/statement/customerInterface/listDept', // 查询所有部门
  User = '/statement/customerInterface/listDeptUser', // 查询所有部门下的所有用户信息
  RecoverOrInvalid = '/statement/dirmanagement/recoverAndLoseEfficacy', // 目录恢复/失效
  Upload = '/statement/dirmanagement/uploadTemplate', // 上传目录模板
  Update = '/statement/dirmanagement/update', //修改目录
  DeleteTemplate = '/statement/dirmanagement/deleteById', // 删除模板
  Start = '/statement/dirmanagement/start' //目录发起流程
}

/**
 * 查询目录管理列表
 * @param params
 */
export function getDirectoryList(params: DirectoryListParams) {
  return http.request<BasicResponseModel>(
    {
      url: Api.List,
      method: 'GET',
      params
    },
    {
      isTransformRequestResult: false
    }
  )
}

/**
 * 目录发起流程
 * @param params
 */
export function sponsorDirectoryFlow(params: SponsorDirectoryFlowParams) {
  return http.request({
    url: Api.Sponsor,
    method: 'POST',
    params
  })
}

/**
 * 目录恢复/失效
 * @param dirId
 */
export function recoverOrInvalidDirectory(dirId: string) {
  return http.request({
    url: Api.RecoverOrInvalid,
    method: 'GET',
    params: { dirId }
  })
}

/**
 * 查询目录详情
 * @param dirId
 */
export function getDirectoryDetail(dirId: string) {
  return http.request(
    {
      url: Api.Detail,
      method: 'GET',
      params: { dirId }
    },
    {
      isShowMessage: false
    }
  )
}

/**
 * 删除目录
 * @param dirId
 */
export function deleteDirectory(dirId: string) {
  return http.request({
    url: Api.Delete,
    method: 'GET',
    params: { dirId }
  })
}

/**
 * 添加资源文件
 * @param params
 */
export function addManagementFile(params: AddDirmanagementParams) {
  return http.request<BasicResponseModel>({
    url: Api.Add,
    method: 'POST',
    params
  })
}

/**
 * @description:  资源文件上传，单文件上传
 */
export function uploadDirectoryFile(params: UploadFileParams) {
  const formData = new FormData()
  formData.append('files', params.file, params.filename)
  formData.append('resourceId', params.resourceId)

  return http.request<BasicResponseModel>({
    url: Api.Upload,
    method: 'POST',
    data: formData,
    headers: {
      'Content-type': ContentTypeEnum.FORM_DATA
    }
  })
}
/**
 * 删除目录模板文件
 * @param dirId
 */
export function deleteDirectoryTemplate(dirId: string) {
  return http.request({
    url: Api.DeleteTemplate,
    method: 'GET',
    params: { dirId }
  })
}

/**
 * 查询所有部门
 */
export function queryDeptList() {
  return http.request(
    {
      url: Api.Dept,
      method: 'POST'
    },
    {
      isShowMessage: false
    }
  )
}

/**
 * 查询所有部门下的所有用户信息
 */
export function DeptUserList() {
  return http.request(
    {
      url: Api.User,
      method: 'POST'
    },
    {
      isShowMessage: false
    }
  )
}

/**
 * 修改目录
 * @param params
 */
export function updateManagementRequest(params: UpdateManagementParams) {
  return http.request<BasicResponseModel>({
    url: Api.Update,
    method: 'POST',
    params
  })
}
